Skip to content

fix(tornado): use get_list() for multi-value headers in tornadoparser - #1118

Closed
abu-tahir-0 wants to merge 1 commit into
marshmallow-code:devfrom
abu-tahir-0:fix/tornado-multivalue-headers
Closed

abu-tahir-0 wants to merge 1 commit into
marshmallow-code:devfrom
abu-tahir-0:fix/tornado-multivalue-headers

Conversation

@abu-tahir-0

Copy link
Copy Markdown

Problem

When parsing headers with Tornado, tornado.httputil.HTTPHeaders.get(key) returns multiple values as a single comma-delimited string (e.g. 'foo,bar'). In WebArgsTornadoMultiDictProxy, iterating over this string when the field is multi-valued (e.g. fields.List(...)) yielded each individual character (['f', 'o', 'o', ',', 'b', 'a', 'r']) instead of the distinct header values ['foo', 'bar'].

Root Cause

WebArgsTornadoMultiDictProxy.getitem unconditionally called self.data.get(key) to retrieve the value. For tornado.httputil.HTTPHeaders, get() concatenates repeated header values with commas, whereas get_list(key) returns the list of individual header values. Additionally, MultiDictProxy.getitem checked getlist and getall, but not Tornado's get_list method name.

Solution

  1. In WebArgsTornadoMultiDictProxy.getitem, check if self.data has get_list when retrieving keys in self.multiple_keys, and call self.data.get_list(key) to obtain the original list of header values.
  2. In MultiDictProxy.getitem, add hasattr(self.data, 'get_list') support alongside getlist and getall.

Testing

  • Added regression test test_it_should_parse_httpheaders_with_multivalue in tests/test_tornadoparser.py testing tornado.httputil.HTTPHeaders with multi-value fields.
  • Ran full test suites: test_tornadoparser.py (34 passed) and test_core.py (139 passed).
  • Ran ruff check and ruff format --check (all passed).

Impact

Allows multi-value headers to be parsed into correct list values under Tornado without character splitting.

Fixes #1109

@sirosen

sirosen commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

This PR violates our AI Policy.

Please read and take time to digest and understand the policy. Sending us LLM outputs without any investment of real effort is actively harmful to the project maintainers and therefore harmful to the project.

@sirosen sirosen closed this Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-value tornado headers are fetched with get() rather than get_list()

2 participants